<?php
########################################################################################
# Empresa :     Tecnopac Informatica;                                                  #
# Autor:        Deiverson Pacheco;                                                     #
# Data Criação: 10/12/2010;                                                            #
########################################################################################
session_start();
header("Cache-control: private");
include_once("../../includes/session.php");


//Linha para formatação de caracteres com acentuação
header("Content-Type: text/html; charset=ISO-8859-1",true);


//======================================================================================
//==> Include obrigatórias no script
//======================================================================================
include_once('../../includes/classes/class.TemplatePower.php');
include_once('../../includes/classes/class.Conexao.php');
include_once('../../includes/classes/class.Geral.php');

//======================================================================================
//==> Inicializar Classes
//======================================================================================
$not  = new Persist;
$not2 = new Persist;
$data = new getData;
$cor  = new ColorTr;
$util = new Util;
$vld  = new ValidarDados;
$sql  = new SqlInjection;

//======================================================================================
//==> Instanciar TemplatePower para juntar o PHP + HTML
//======================================================================================
$tpl  = new TemplatePower('../../html/geral/popup_cadastrar_associados.html');
$tpl->prepare();


//======================================================================================
//==> Recebe variaveis de pesquisa
//======================================================================================
$id  = @$_GET['id'];
$id_pess  = @$_GET['id_pess'];
$tpl->assign('id_pess',$id_pess);

$evento = @$_GET['evento'];

//======================================================================================
//==> Executa case conforme evento
//======================================================================================

if(isset($evento)){
	switch($evento){
		
		case 'inserir': {
			
			$pessoa 	 = @$sql->tratar($_GET['pessoa'],10);
			$nome 		 = @$sql->tratar($_GET['nome'],10);
			$doc  		 = @$sql->tratar($_GET['doc'],10);
			$comercial   = @$sql->tratar($_GET['comercial'],10);
			$email  	 = @$sql->tratar($_GET['email'],10);				
			
			//captura data e hora atual
			$dt = $data->getDataHoje('-').' '.$data->getHora();
			
		
			$not->sql = "insert into cadastro
						(pessoa, nome_razao, doc, comercial, email, uid_cadastro, dt_hora_cadastro, ativo) 
						 values 
						('$pessoa', '$nome', '$doc', '$comercial', '$email', '$ID_USUARIO', '$dt', 'Sim')";
			$not->ins();
			
			$not2->sql = "SELECT MAX(id) AS id_ultimo FROM cadastro";
			$not2->ler();
			$not2->ini();
			
			extract($_GET);
			//-- Add em contatos_associados		
			$not->sql = "insert into contatos_associados
						(id_cadastrof, id_cadastroj, data_hora, uid) 
						 values 
						('$not2->id_ultimo', '$id_pess', '$dt', '$ID_USUARIO')";
			$not->ins();
			
			header("location: popup_contatos_associados.php?id=".$id_pess);

		
		break;
		}
		
		
	}
}


//======================================================================================
//==> Enviar página unificada PHP + HTML
//======================================================================================
$tpl->showUnAssigned( false );  // para debug. na hora de publicar, setar para false
$tpl->printToScreen();
?>